package com.idanchuang.count.dao;

import com.idanchuang.count.core.entity.IncrementCommand;
import com.idanchuang.count.core.entity.ResetCommand;
import org.springframework.data.redis.core.script.RedisScript;

import java.util.List;

/**
 * @author Richard_yyf
 * @version 1.0 2021/5/27
 */
public interface CountDao {

    /**
     * get counter value by key
     * return null when key not exist
     *
     * @param key counter's key
     * @return the val of counter
     */
    Long getCount(String key);

    /**
     * get values of a batch of counter by keys
     *
     * @param keys counters' keys
     * @return counters' values , 顺序和keys一致, 如果key不存在，则对应顺序的值为null
     */
    List<Long> multiGetCount(List<String> keys);

    /**
     * do incr operation
     *
     * @param incrementCommand update command
     * @return 自增后的值
     */
    Long incr(IncrementCommand incrementCommand);

    /**
     * do incr operations in the order of commands
     *
     * @param incrementCommands update commands
     * @return 自增后的结果
     */
     List<Long> batchIncr(List<? extends IncrementCommand> incrementCommands);

    /**
     * do set operation in the order of commands
     *
     * @param resetCommands reset command
     */
    void batchSet(List<ResetCommand> resetCommands);

    /**
     * 执行 lua 脚本
     *
     * @return result
     */
    Long executeScript(RedisScript<Long> script, List<String> keys, String... args);
}
